home *** CD-ROM | disk | FTP | other *** search
- /****************************************************************************
- * Copyright (c) 1993, BSDI. All rights reserved.
- * Library Name... Object Engine
- * File Name...... objeng.hpp
- * Comments....... This file contains the class definitions and #defines
- ***************************************************************************/
- #ifndef _OEDBH_
- #define _OEDBH_
-
- #include <string.h>
- #include <time.h>
- #include <pxengine.h>
-
- #ifndef TRUE
- #define TRUE 1
- #define FALSE 0
- #endif
-
- #ifndef NULL
- #define NULL 0
- #endif
-
- const int MAXFIELDS=64;
- const int OE_MAXTABLES=32;
- const int NOTINIT = 0;
- const int FAIL = 1;
- const int READY = 2;
-
- class OEList;
-
- //-----------------------------------------------------------
- typedef struct {
- char TableName[12];
- TABLEHANDLE tHdl;
- RECORDHANDLE rHdl;
- } OEHandle;
-
-
- //-----------------------------------------------------------
- class ObjEng {
- private:
- int status;
- int OESaveChanges;
- char filedir[64];
- OEHandle RegisteredTables[OE_MAXTABLES];
- TABLEHANDLE tHdl;
- RECORDHANDLE rHdl;
- int TableInit();
- public:
- #ifdef _Windows
- ObjEng(char *clientName, int shareMode, int bufsize, int maxContainer, int saveChanges, char *fd);
- ObjEng(char *clientName); //Uses all defaults.
- #else
- ObjEng(int bufsize, int maxContainer, int saveChanges, char *fd);
- ObjEng(); //Uses all defaults.
- #endif
- ~ObjEng();
- int GetIndex(long &index, int listFlag);
- int Register(OEHandle &oehandle, char **FieldNames, char **FieldTypes, FIELDHANDLE *IdxFieldHandles, int nFields, int nIdxFields);
- int IsRegistered(OEHandle &oehandle);
- int AttachChild(long &parent, const char *tableName, const long &objectID);
- int DetachChild(const long &parent, const long &child);
- int GetChild(long &parent, char *tbl, long &child, int mode);
- const char *GetFileDir() { return filedir; }
- const int GetStatus() { return status; }
- };
-
-
- //-------------------------------------------------------------------------
- class PersistClass {
- protected:
- friend OEList;
- PersistClass *next;
-
- // Holds the name of and Paradox Engine handles for the table that
- // matches this persistant class.
- OEHandle oehandle;
-
- // The objectID is at the center of the persistance system.
- // It is the "link" between the object and a db table record.
- // It is assigned when a virgin object is Stored and cleared when
- // Destroyed. Each of the link functions resets objectID to that
- // of the db record being retrieved when the client object is filled from
- // the database. The copy constructor and assignment operator do NOT
- // copy it since that would mix up two client objects - contrary to the
- // philosophy of the system.
- long objectID;
-
- // "C" Types - used during the "LinkToField" function.
- char localtypes[MAXFIELDS];
-
- // Status holds the most recent Engine return code. Most functions
- // return this value for user to test against. Uses engine error
- // codes exclusively!
- int status;
-
- // DeleteFlag tells a container whether this object should be deleted
- // when the container is destroyed or during a call to OEList::Remove.
- // By default, it is 0 UNLESS the object was automatically created
- // during a load from the database. You can set this if you want the
- // object engine to delete objects in a list for you (see below).
- char deleteFlag;
-
- // Retrieve is defined by derived classes to indicate how the linking
- // required by the functions below is actually implemented. It
- // must be in the derived classes since they are the ones to know the
- // structure of the object/db record.
- virtual int Retrieve() = 0;
- // Utility to copy PersistClass data without the objectID link.
- void Copy(PersistClass &pc);
- public:
- // Default class constructor.
- PersistClass(char *name);
- // Used in the copy constructor.
- PersistClass() {}
-
- // Store places the contents of an object into the data table. If
- // the object is not linked (no objectID) then an objectID is assigned.
- // Otherwise, the contents of the object are placed in the record
- // corresponding to the objectID.
- virtual int Store() = 0;
-
- // Table/C++ Class "Linking" functions - allow class instances to
- // be associated with DB records.
- virtual int LinkToKey(int, int);
- int LinkToRecord(int position);
- int LinkToField(char *fieldname, void *value, int mode);
- int LinkToID(const long &ID);
- int LinkToFirst();
- int LinkToLast();
- int LinkToNext();
- int LinkToPrev();
-
- // "Unlinking" functions. Also, the copy constructor and assignment
- // operator will unlink the recipient of the copy/assignment.
- void Unlink();
- virtual int Destroy();
-
- // Utilities
- int NRecs(RECORDNUMBER & nrecs);
- int OEPutDate(const int &, const struct tm &);
- int OEGetDate(const int &, struct tm &);
- const int GetStatus() { return status; }
- TABLEHANDLE GetTblHdl() { return oehandle.tHdl; }
- RECORDHANDLE GetRecHdl() { return oehandle.rHdl; }
- const char *GetTblName() { return oehandle.TableName; }
- long GetObjectID() { return objectID; }
- char GetDeleteFlag() { return deleteFlag; }
- char SetDeleteFlag(char flag) { return(deleteFlag = flag); }
- };
-
-
- //----------------------------------------------------------------
- class OEList {
- private:
- long listID;
- int status;
- int referenceCount;
- PersistClass *head, *cur;
- public:
- OEList();
- OEList(long inID);
- int Init();
- ~OEList();
- void Insert(PersistClass *curelem);
- void Remove();
- PersistClass *operator()();
- PersistClass *operator++(int);
- void Reset() { cur = head; }
- int Count();
- void Clear();
- void AddReference() { referenceCount++; }
- char DeleteOK() { referenceCount--; return(referenceCount == 1); }
- const int GetStatus() { return status; }
- const long GetListID() { return listID; }
- };
-
-
- // This "global" function provides the mapping from table names
- // to table objects for the automatic "has-a" link storage/retrieval.
- PersistClass *GetPersistClass(char *tbl, const long &inID);
-
-
- #endif
-